#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
ll a, b;
pll calc(int n, ll m) {
  if (n == 0) return pll(0, 0);
  ll len = 1ll << (n - 1), cnt = 1ll << (2 * n - 2);
  pll pos = calc(n - 1, m % cnt);
  ll x = pos.first, y = pos.second;
  int z = m / cnt;
  if (z == 0)
    return pll(y, x);
  else if (z == 1)
    return pll(x, y + len);
  else if (z == 2)
    return pll(x + len, y + len);
  else
    return pll(len * 2 - 1 - y, len - 1 - x);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> a >> b;
    pll p1 = calc(n, a - 1);
    pll p2 = calc(n, b - 1);
    double ans = sqrt(pow(10.0 * (p1.first - p2.first), 2) +
                      pow(10.0 * (p1.second - p2.second), 2));
    cout << fixed << setprecision(0) << ans << endl;
  }
  return 0;
}